<?php 
/**
 * 统计控制器
 * @Author    紫梦
 * @DateTime  2018-02-12
 * @copyright 响响租车
 * @version   1.0
 */
namespace app\wxapp\controller;
use app\common\model\Agency;
use app\common\model\Brand;

class Charts extends Base
{
    public static function brand()
    {

        $brand = Brand::column('id');
        $model = Brand::withCount(['cars'])->select($brand);
        foreach ($model as $key => $value) {
            $array[$key]['value'] = $value->cars_count;
            
            $array[$key]['name'] = $value->name;
        }
        rsort($array);

        return $array;
    }

    public static function agency()
    {
        $agency = Agency::where('id','>',1)->column('id');
        $model = Agency::withCount(['cars'])->select($agency);
        foreach ($model as $key => $value) {
            $array[$key]['value'] = $value->cars_count;
            
            $array[$key]['name'] = $value->name;
        }
        rsort($array);

        return $array;
    }
}